Page({
  /**
   * 页面的初始数据
   */
  data: {
    url: '',
    corpKey: '',
    jyqsDataInfo: [],
    detail: {}
  },
  getInfo() {
    getApp().globalData.request(
      "/map/getICInfoByCorpKey", {
        corpKey: this.data.corpKey,
      },
      "POST"
    ).then((res) => {
      console.log(res, '经营趋势')
      this.setData({
        detail: res.data.jkJbxxSfxx
      })
      // 旧的经营趋势
      // res.data.businessTrends.forEach(e => {
      //   this.data.jyqsDataInfo.push({
      //     xData: e.x,
      //     yData1: e.y1,
      //     yData2: e.y2,
      //     title: e.title,
      //     unit: e.unit,
      //     type: "line",
      //   })
      //   this.setData({
      //     jyqsDataInfo: this.data.jyqsDataInfo
      //   })
      // });
    })
  },
  async getNewJy() {
    // 新版权限控制经营趋势
    const res = await getApp().globalData.request(
      "/map/queryCorpBusinessTrendInfo", {
        corpCredit: this.data.corpKey,
      },
      "POST"
    )
    console.log(res, 'res');
    let needList = []
    res.data.businessTrendList.forEach((pl) => {
      let nObj = {};
      if (
        pl.hasStatisticalYear == 1 &&
        (pl.hasCityAvg == 1 || pl.hasIndustAv == 1 || pl.hasSelfData == 1)
      ) {
        nObj.isNew = true;
        nObj.title = pl.title;
        nObj.unit = pl.unit;
        nObj.type = 'line';
        nObj.tabelName = this.getName(pl.title);
        nObj.xData = pl.statisticalYear;
        nObj.isAuthorized = res.data.isAuthorized;
        nObj.y1 =
          pl.hasSelfData == 1 ?
          pl.unit == "金额" ?
          pl.selfData.map((pre) => (pre * 0.000001).toFixed(2)) :
          pl.selfData : [];
        nObj.y2 =
          pl.hasIndustAvg == 1 ?
          pl.unit == "金额" ?
          pl.industryAvg.map((pre) => (pre * 0.000001).toFixed(2)) :
          pl.industryAvg : [];
        nObj.y3 =
          pl.hasCityAvg == 1 ?
          pl.unit == "金额" ?
          pl.cityAvg.map((pre) => (pre * 0.000001).toFixed(2)) :
          pl.cityAvg : [];
      }
      if (Object.keys(nObj).length > 0) {
        needList.push(nObj);
      }
    });
    console.log(needList, 'needList');
    this.setData({
      jyqsDataInfo: needList
    })
  },
  getName(title) {
    let name = "";
    switch (title) {
      case "营业收入变动趋势":
        name = "营业收入";
        break;
      case "核心员工变动趋势":
        name = "核心员工";
        break;
      case "纳税变动趋势":
        name = "纳税";
        break;
      case "净利润变动趋势":
        name = "净利润";
        break;
      case "社保变动趋势":
        name = "社保";
        break;
      default:
        break;
    }
    return name;
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.data.corpKey = options.corpKey
    this.getInfo()
    this.getNewJy()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {},

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {},

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {},

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {},
});